﻿Public Class LoaiNhanVienDAO

    Private connect As ConnectDB
    Private sqlstr As String


    Public Sub New()
        connect = New ConnectDB()
    End Sub

    Public Function IsUpLNV(ByVal emp As LoaiNhanVienDTO, ByVal flag As Boolean)
        Dim IDKV As String = emp.Mã_Loại_NV
        Dim TenKV As String = emp.Tên_Loại_NV

        '-------------------------------------------'
        If flag = True Then
            sqlstr = "INSERT LOAINHANVIEN (TenLoaiNV)" & _
                        " VALUES('" & TenKV & "')"
        Else
            sqlstr = "UPDATE LOAINHANVIEN SET TenLoaiNV   = '" & TenKV & _
                                    "' WHERE MaIDLoaiNV  = '" & IDKV & "'"

        End If
        Return connect.Execute(sqlstr)
    End Function

    Public Function DeleteLNV(ByVal emp As LoaiNhanVienDTO)
        Dim IDKV As String = emp.Mã_Loại_NV
        sqlstr = "DELETE LOAINHANVIEN WHERE IDLoaiNV = '" & IDKV & "'"
        Return connect.Execute(sqlstr)
    End Function

    Public Function Getdata() As List(Of LoaiNhanVienDTO)
        Dim i As Integer
        Dim makv, tenkv As String
        Dim emp As LoaiNhanVienDTO
        Dim kvList As New List(Of LoaiNhanVienDTO)
        Dim dt As New DataTable
        dt = connect.GetData("Select * From LOAINHANVIEN")

        For i = 0 To dt.Rows.Count() - 1
            makv = dt.Rows(i)("IDLoaiNV").ToString
            tenkv = dt.Rows(i)("TenLoaiNV").ToString

            emp = New LoaiNhanVienDTO(makv, tenkv)
            kvList.Add(emp)
        Next
        Return kvList
    End Function


End Class
